package com.mew.chess.core.game.bjl.game.message;

import com.zebra.common.ZebraBaseMessage;
import io.netty.buffer.ByteBuf;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Data
@ToString
@NoArgsConstructor
public class EnterResponseMessage extends ZebraBaseMessage<EnterResponseMessage> {

    private UserMessage userMessage;
    private int[] roomBetArray;
    private long lastBetNumber; // 上把 押注
    private long maxBetLimit;//最大压注限制

    private int linkType;
    private int remainTime;

    private long ino;//局号
    private int cardNumber;//牌数
    private Map<Integer,Long> typebetNumber;//各个区域压注
    private List<Integer> bankerCards;//庄家牌
    private List<Integer> idleCards;//闲家牌
    private List<HistoryMessage> historyVOList;    //历史记录
    private Collection<UserMessage> bigRList;    //大玩家

    @Override
    public void write(ByteBuf b) {

        userMessage.write(b);
        writeIntArray(b, this.roomBetArray);
        writeLong(b, this.lastBetNumber);
        writeLong(b,this.maxBetLimit);
        writeInt(b, this.linkType);
        writeInt(b, this.remainTime);
        writeLong(b,ino);
        writeInt(b,cardNumber);
        writeInt(b,typebetNumber.size());
        typebetNumber.entrySet().stream().forEach(entry->{
            writeInt(b,2);
            writeLong(b,entry.getKey());
            writeLong(b,entry.getValue());
        });

        writeInt(b,bankerCards.size());
        for (Integer bankerCard : bankerCards) {
            writeInt(b,bankerCard);
        }
        writeInt(b,idleCards.size());
        for (Integer idleCard : idleCards) {
            writeInt(b,idleCard);
        }

        writeInt(b,historyVOList.size());
        for (HistoryMessage historyMessage : historyVOList) {
            historyMessage.write(b);
        }
        writeInt(b,bigRList.size());
        for (UserMessage userMessage : bigRList) {
            userMessage.write(b);
        }
    }

    @Override
    public EnterResponseMessage read(ByteBuf b) {
        EnterResponseMessage message = new EnterResponseMessage();
        UserMessage userMessage=new UserMessage();
        userMessage.read(b);
        message.setUserMessage(userMessage);
        message.roomBetArray = readIntArray(b);
        message.lastBetNumber = readLong(b);
        message.linkType = readInt(b);
        message.remainTime = readInt(b);

        return message;
    }
}
